package tomcat.Impl;

import tomcat.HttpServletRequest;
import tomcat.HttpServletResponse;
import tomcat.HttpSession;
import tomcat.ServletException;

import java.io.IOException;
import java.io.PrintWriter;

public class SessionServlet extends HttpServletImpl{
    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        String name = request.getParameter("name");
        PrintWriter out = response.getWriter();
        HttpSession session = request.getSession();
        response.setContentType("text/html;charset=utf-8");
        if (name!=null){
            // 保存数据到会话中
            session.setAttribute("name", name);
            out.println("<h1>请求参数值name : "+name+"</h1>");
        } else {
            name = (String) session.getAttribute("name");
            out.println("<h1>会话中的值name : "+name+"</h1>");
        }
    }
}
